using System;
using System.Diagnostics.Contracts;

namespace Windy.Transformations
{
    public class BlockTransformRule<TKey> : ITransformRule<TKey>, IVoidTransformRule<TKey>
    {
        #region Initializers

        #region Constructors

        public BlockTransformRule(Func<TKey, bool> condition)
        {
            Contract.Requires(condition != null, "condition is null.");

            Initialize(condition);
        }

        public BlockTransformRule(TKey key)
        {
            Initialize((k) => k.Equals(key));
        }

        public BlockTransformRule()
        {
            Initialize((k) => true);
        }
        #endregion

        protected void Initialize(Func<TKey, bool> condition)
        {
            Contract.Requires(condition != null, "condition is null.");

            this.Condition = condition;
        }

        #endregion

        #region Properties

        protected Func<TKey, bool> Condition { get; private set; }

        public TransformRuleTypes RuleType { get { return TransformRuleTypes.VoidTransformRule; } }

        #endregion

        #region Methods

        public bool CheckCondition(TKey key)
        {
            return Condition(key);
        }

        #endregion
    }
}
